package com.xyw.code.efficient_programming.lambda.cart;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by xuyiwei on 2020/1/6 10:11
 */
public class CartService {

    public static List<Sku> cartSkuList = new ArrayList<Sku>(){
        {
            add(new Sku(1,"无人机",10d,1,10d,CategoryEnum.ELECTRONICS));
            add(new Sku(2,"VR",466.1d,2,932.2,CategoryEnum.ELECTRONICS));
            add(new Sku(3,"漫画书",30d,2,60.0,CategoryEnum.BOOKS));
            add(new Sku(4,"衬衫",70D,2,140D,CategoryEnum.CLOTHING));

        }
    };

    public static List<Sku> getCartSkuList(){
        return cartSkuList;
    }

    //得到电子产品
    public static List<Sku> filterElectronicsSkus(List<Sku> cartSkuList){

        return cartSkuList.stream().filter(n->
                n.getSkuCategory().equals(CategoryEnum.ELECTRONICS)

        ).collect(Collectors.toList());
    }

    //得到电子产品
    public static List<Sku> filterElectronicsSkus(List<Sku> cartSkuList,CategoryEnum categoryEnum){
        return cartSkuList.stream().filter(n->
                n.getSkuCategory().equals(categoryEnum)

        ).collect(Collectors.toList());
    }

    //得到电子产品
    public static List<Sku> filterElectronicsSkus(List<Sku> cartSkuList,SkuPredicate skuPredicate){
        return cartSkuList.stream().filter(n->
                skuPredicate.test(n)

        ).collect(Collectors.toList());
    }
}
